﻿using Common.Service;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RabitPart.WritedPartApi.Application.Comman.RBACfile;
using RabitPart.WritedPartApi.Application.Comman.RBACfiless;

namespace RabitPart.WritedPartApi.Controllers
{
    /// <summary>
    /// 控制器--RBAC用户-权限-角色
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RBACuserpermroleController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<RBACuserpermroleController> logger;

        public RBACuserpermroleController(IMediator mediator, ILogger<RBACuserpermroleController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 添加--角色用户
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>添加--角色用户</returns>
        [HttpPost]
        public async Task<ApiResult> CreateUserRole(RBACuserroleCreateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("添加角色用户信息异常" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 添加--权限角色
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>添加--权限角色</returns>
        [HttpPost]
        public async Task<ApiResult> Createroleprem(RBACrolepermCreateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("添加权限角色信息异常" + ex.Message);
                throw;
            }
        }

    }
}
